/*
Ejemplo de XML en el web resource "test_xml":
<attributes>
    <attribute name="accountcategorycode" value="1" showattributes="primarycontactid,accountnumber" hideattributes="" />
    <attribute name="accountcategorycode" value="2" showattributes="" hideattributes="primarycontactid,accountnumber" />
</attributes>
*/
var xml_loaded=false;
var xmlPath = "../WebResources/new_test_xml";
var doc = new ActiveXObject("Microsoft.XMLDOM");

function GestionVisibilidad()
{
   if (!xml_loaded)
   {
      doc.preserveWhiteSpace = true;
      doc.async = false;
      doc.load(xmlPath);
      xml_loaded=true;
   }
   var nodelist;
   var nodePath = "//attributes/attribute";
   nodelist = doc.selectNodes(nodePath);
   for (var i = 0; i < nodelist.length; i++) 
   {
      var attributename= nodelist(i).attributes[0].value;
      var attributevalue= nodelist(i).attributes[1].value;
      var showattributes= nodelist(i).attributes[2].value;
      var hideattributes= nodelist(i).attributes[3].value;
      if (attributevalue==""+Xrm.Page.getAttribute(attributename).getValue())
      {
		//realizar las acciones
		var arrshowattributes=showattributes.split(","); 
		var arrhideattributes=hideattributes.split(","); 
		for (j=0;j<arrshowattributes.length;j++) 
		{
             if (Xrm.Page.getControl(arrshowattributes[j])) 
				Xrm.Page.getControl(arrshowattributes[j]).setVisible(true);
		}
		for (j=0;j<arrhideattributes.length;j++) 
		{
             if (Xrm.Page.getControl(arrhideattributes[j]))   
				Xrm.Page.getControl(arrhideattributes[j]).setVisible(false);
		}
      }
   }
}